package com.logic.ui.custom;

import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;

/**
 * date wheel adapter using to show date values
 * @author Jeff 2011.09.30 
 */
public class DateWheelAdapter implements WheelAdapter{

	/** The default min value */
	public static final int DEFAULT_MAX_VALUE =365;

	/** The default max value */
	private static final int DEFAULT_MIN_VALUE = 0;
	
	Calendar cal=Calendar.getInstance(TimeZone.getDefault() ,Locale.getDefault());		
	int length =cal.getMaximum(Calendar.DAY_OF_YEAR);
	
	@Override
	public int getItemsCount() {
		if(length!=0)
			return length;
		else 
			return DEFAULT_MAX_VALUE;
	}

	@Override
	public String getItem(int index) {	
		if(index >=0&&index<length){
			cal.set(Calendar.DAY_OF_YEAR,index);
			//System.out.println(cal.get(Calendar.MONTH)+1+"  "+cal.get(Calendar.DAY_OF_MONTH));
			String str=String.format("%1$2d-%2$2d",cal.get(Calendar.MONTH)+1,cal.get(Calendar.DAY_OF_MONTH));			
			return str;
		}		
		return null;	
	}

	@Override
	public int getMaximumLength() {
		// TODO Auto-generated method stub
		return -1;
	}

}
